<template>
    <view :style="themeColor">
        <view class="order-submit-list" v-for="(item, index) in data.List" :key="index">
            <view class="order-item">
                <order-submit-item
                    v-for="(proItem, subindex) in item.CarList"
                    :key="subindex"
                    :data="item"
                    :item="proItem"
                    @changePolicy="changePolicy"></order-submit-item>
            </view>
            <!-- 			<view class="policy-price-box" v-if="item.Discount>0">
				<text class="label-text">优惠:{{item.PolicyName}}</text>
				<text>- ￥{{item.Discount}}</text>
			</view>
			<view v-if="item && item.GiftList && item.GiftList.length>0">
				<text class="price-text">赠品</text>
				<view class="" v-for="(giftItem,giftIndex) in item.GiftList" :key="giftIndex">
					<text>{{giftItem.ProductName}} x{{giftItem.Amount}}</text>
				</view>
			</view>
			<view  class="policy-after-price" v-if="item.Discount>0 && false">
				<text class="price-text">￥{{getTotal(item)}}</text>
			</view> -->
        </view>
    </view>
</template>

<script>
import { mapGetters } from "vuex"
import { getProductDataBySubmit } from "@/service/api/order.js"
import orderSubmitItem from "@/pages_shop/components/order/order-submit-item.vue"
export default {
    components: {
        orderSubmitItem,
    },
    data() {
        return {
            param: {},
            data: {},
            ids: "",
            isFrist: true,
        }
    },
    onLoad(e) {
        this.ids = e.ids
        this.param = JSON.parse(e.param)
        this.param.orderPolicy.carPolicyList = []
    },
    watch: {
        //监听更新
        getUpRemarkView(e) {
            this.getData()
        },
    },
    computed: {
        ...mapGetters(["getUpRemarkView"]),
    },
    mounted() {
        this.getData()
    },

    methods: {
        getTotal(item) {
            let total = 0
            item.CarList.forEach((e) => {
                total += e.TotalMoney
            })
            return total - item.Discount
        },
        changePolicy(item) {
            let hasIn = false
            let carPolicyList = this.param.orderPolicy.carPolicyList

            if (carPolicyList.length > 0) {
                carPolicyList.filter((e) => {
                    if (e.CarId == item.CarId) {
                        hasIn = true
                        return (e.PolicyId = item.PolicyId)
                    }
                })
            }
            if (!hasIn) {
                carPolicyList.push(item)
            }
            this.getData()
        },
        getData() {
            getProductDataBySubmit(this.param).then((res) => {
                if (res.Data && res.Data.List) {
                    this.data = res.Data
                    this.param.orderPolicy.carPolicyList = []
                    if (this.isFrist) {
                        this.data.List.forEach((e) => {
                            e.CarList.forEach((car) => {
                                let obj = {
                                    CarId: car.ID,
                                    PolicyId: e.PolicyId,
                                }
                                this.param.orderPolicy.carPolicyList.push(obj)
                            })
                        })
                    }
                    if (!this.ids) {
                        let ids = ""
                        this.param.orderPolicy.carPolicyList.forEach((e) => {
                            ids = ids + e.CarId + ","
                        })
                        this.ids = ids
                        this.ids = this.ids.slice(0, this.ids.length - 1)
                    }
                }
            })
        },
    },
}
</script>

<style lang="scss">
page {
    background: #f1f1f1;
}
.order-submit-list {
    background-color: $color-white;
    border-radius: $border-radius-10;
    margin-bottom: 20rpx;
    padding: 0 $app-page-padding 0 $app-page-padding;
    border-top: 12rpx solid #f1f1f1;
    .policy-price-box {
        display: flex;
        flex-direction: row;
        height: 60rpx;
        align-items: center;
        .label-text {
            flex: 1;
        }
    }
    .policy-after-price {
        display: flex;
        flex-direction: row;
        height: 60rpx;
        align-items: center;
        justify-content: flex-end;
    }
}
</style>
